package com.snail.xgcd.controller;

import com.github.pagehelper.PageHelper;
import com.snail.xgcd.bean.Member;
import com.snail.xgcd.bean.Single;
import com.snail.xgcd.bean.User;
import com.snail.xgcd.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/member")
@RestController
public class MemberController {

    @Autowired
    private MemberService memberService;

    @RequestMapping("/list")
    public Single findAll(Member member,Integer pageSize,Integer pageNum){
        return memberService.findAll(member,pageSize,pageNum);
    }

    @RequestMapping("/del")
    public Single del(String id){
        return memberService.deleteByPrimaryKey(Long.parseLong(id));
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Single add(@RequestBody Member member){
        return memberService.insert(member);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Single update(@RequestBody Member member){
        return memberService.updateByPrimaryKeySelective(member);
    }

    @RequestMapping(value = "/charge",method = RequestMethod.POST)
    public Single charge(@RequestParam("id") String id , @RequestParam("money") String money){
        return memberService.charge(id,money);
    }

    @RequestMapping(value = "/consume",method = RequestMethod.POST)
    public Single consume(@RequestParam("id") String id , @RequestParam("money") String money){
        return memberService.consume(id,money);
    }

}
